


require("engin.config.EnginInit")
require("app.config.init")



local MyApp = class("MyApp", cc.load("mvc").AppBase)


function MyApp:ctor()
    MyApp.super.ctor(self)
end






function MyApp:run()

    math.randomseed(os.time())

    self:enterScene(SceneConstants.LoginScene())
  	
  	
  	--[[
  
  	local param = SceneConstants.FightLoadingScene();
    param.param ={
    	level =  2
    }
    self:enterScene(param)
    ]]
end





--[[

]]
function MyApp:enterScene(sceneParam)
	local sceneName,backScaneName,isPhysicsWorld, param = sceneParam.sceneName,sceneParam.backScaneName,sceneParam.isPhysicsWorld, sceneParam.param;
	

	local function enterSceneFun(sceneName, args, transitionType, time, more)
	    local scenePackageName = "app.scenes." .. sceneName
	    MyApp.isPhysicsWorld = isPhysicsWorld;
	     
	    local sceneClass = require(scenePackageName)
	    local scene = sceneClass.new(args)
	    display.runScene(scene, transitionType, time, more)
	    
	  
	    return scene
	end

	if not param then param = {} end
	param.sceneName = sceneName;
    local scene = enterSceneFun(sceneName,param)--, ...);
    
    self.previousSceneName_ = self.currentSceneName_;
    self.currentSceneName_ = sceneName;
    self.currentScene_ = scene;
end




function MyApp:back()
	local sceneParam =  clone(SceneConstants[self.currentSceneName_]()) --SceneConstants.FightScene();
	if sceneParam and sceneParam.backSceneName then 
		self:enterScene(SceneConstants[sceneParam.backSceneName]())
	else	
		self:exit();
	end
end




function MyApp:exit()
    cc.Director:getInstance():endToLua()
    if device.platform == "windows" or device.platform == "mac" then
        os.exit()
    end
end


return MyApp
